export default {
  data() {
    return {
      show: false,
      current: '', //当前选中id
      value: '', //uid的值
      userList: [], //成员列表
      list: [],
      companyId: '',
      content: '确认转让超管',
      userInfo: '', //超管列表
      // role: '', //角色
      info: {}, //当前用户信息
      listIndex: 1, //当前页
      status: 'loading',
    }
  },
  created() {
    // this.role = this.$store.state.user.userInfo.role
    this.info = this.$store.state.userInfoDetail.user
    this.getCompanyInfo()
    this.userList.shift()
    this.zhs()
  },
  onLoad(op) {
    // console.log(op,'123')
    // this.companyId = op.companyId
    this.companyId = this.$store.state.companyId
    // console.log(this.$store.state.companyId)
  },
  methods: {
    //我的企业信息
    async getCompanyInfo() {
		  try {
		    let data = {
		      StoreId: this.$store.state.userInfoDetail.store.storeId, //'de39ade6cc0944ac99e1a02cc8f7c729'
		    }
		    const res = await this.$api.company.getCompanyInfo(data)
		    let companyIds = res.data.companyId //存公共方法六里面
        this.getCompanyMemberList(companyIds)
		  } catch (e) {
		    console.log(e)
		  }
    },
    more() {
      this.getCompanyMemberList()
    },
    zhs() {
      let role = this.$store.state.user.userInfo.role
      // console.log(this.$store.state.user.userInfo.role, 'vuex')
      if (role === 0) {
        this.role = '员工'
      } else if (role === 1) {

        this.role = '管理员'
      } else if (role === 2) {

        this.role = '超级管理员'
      }
    },
    async onConfirm() {
      let storeId = uni.getStorageSync('userInfoDetail').store.storeId
      try {
        let data = {
          'account_Id': this.current,
          'store_Id': storeId
        }
        const res = await this.$api.company.transferSuperAdmin(data)
        this.$refs.uToast.show({
          title: '转让成功',
          type: 'success',
          back: true
        })
      } catch (e) {
        console.log(e)
      }
    },
    open() {
      if(this.current===''){
        this.$refs.uToast.show({
				  title: '请选择转让员工',
				  type: 'error',
        })
      }else{
        this.show = true
      }
    },
    moreStatus(status) {
      this.status = status
    },
    //成员列表
    async getCompanyMemberList(companyIds) {
      this.status = 'loading'
      try {
        let data = {
          'PageIndex': this.listIndex,
          'PageSize': 5,
          'CompanyId': companyIds //'f1b343b44a6648c68349d406b62e0c7a'
        }
        const res = await this.$api.company.getCompanyMemberList(data)

        this.userList = [...this.userList, ...res.data.list]
        if (res.data.total <= 10) {
          this.status = 'nomore'
        } else {
          this.moreStatus(res.data.list.length !== 0 ? 'loadmore' : 'nomore')
        }
        if (res.data.list.length === 0) return false
        this.listIndex += 1 // 当前页加1

      } catch (e) {
        console.log(e)
      }
    },
    choose(id) {
      this.current = id.target.value
      for (let i = 0; i < this.userList.length; i++) {
        if (this.userList[i].value === id.target.value) {
          this.current = i
          break
        }
      }

    }
  }
}
